package org.example.controller;

import org.example.config.DynamicDataSourceContextHolder;
import org.example.dto.Dog;
import org.example.mapper.DogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/dataSource")
public class TestController {

    @Autowired
    private DogMapper dogMapper;

    @RequestMapping("/demo")
    public List<Dog> list(){
        DynamicDataSourceContextHolder.setDataSource("d1");

        List<Dog> list = dogMapper.findList();

        DynamicDataSourceContextHolder.clearDataSource();
        return list;
    }

}
